/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef INTROSIGHT_HH
#define INTROSIGHT_HH
//! \addtogroup introsight_framework
//@{

// INCLUDES
#include "util.hh"
#include "refcnt.hh"

// DEFINITIONS (common to introsight)

// coordinates
#define IS_WX                 0 // window coordinate position x
#define IS_WY                 1 // window coordinate position y
#define IS_WXY                2 // window coordinate 2D
#define IS_WW                 2 // window coordinate width
#define IS_WH                 3 // window coordinate height
#define IS_WXYWH              4 // window coordinate frame
#define IS_X                  0 // x coordinate index
#define IS_Y                  1 // y coordinate index
#define IS_Z                  2 // z coordinate index
#define IS_W                  3 // w coordinate index
#define IS_2D                 2 // size of 2D vector (xy)
#define IS_3D                 3 // size of 3D vector (xyz)
#define IS_4D                 4 // size of 4D vector (xyzw)

// angles
#define IS_AZIM               0 // azimut
#define IS_ELEV               1 // elevation
#define IS_BANK               2 // banking
#define IS_SPHERIC            3 // spheric coordinates

// colors
#define IS_RED                0
#define IS_GREEN              1
#define IS_BLUE               2
#define IS_ALPHA              3
#define IS_RGBA               4

// time
#define IS_USEC_SEC           1000000      // number of usec in a sec
#define IS_USEC_NO_REQ        (5*USEC_SEC) // interval when no refresh required

// render_obj status
#define IS_STATUS_ANY         0
#define IS_STATUS_SELECTED    (1<<0)   // cursor over object
#define IS_STATUS_CSELECTED   (1<<1)   // cursor over object child
#define IS_STATUS_FOCUS       (1<<2)   // object has focus exclusivity
#define IS_STATUS_FOCUS_MASK  0xff
#define IS_STATUS_FOCUS_ROT   8
#define IS_STATUS_FOCUS_AC(a) (1<<2 | (a)<<IS_STATUS_FOCUS_ROT) // object has focus exclusivity with action a == EM_ACTION_TYPE_X
#define IS_STATUS_SAME(a, b)  \
    (((a) & (b) & IS_STATUS_FOCUS_MASK) &&	\
     (!((a)&(~IS_STATUS_FOCUS_MASK)) ||		\
      !((b)&(~IS_STATUS_FOCUS_MASK)) ||		\
      ((a)>>IS_STATUS_FOCUS_ROT)==((b)>>IS_STATUS_FOCUS_ROT)))

// RENDR_OBJ TYPES
#define IS_TYPE_ANY           0x00     // represents any base and derived objects
#define IS_TYPE_NONE          0x01     // represents no object
#define IS_TYPE_BASE          0x02     // render_obj base object
#define IS_TYPE_FRAME         0x03     // render_obj_frame
#define IS_TYPE_CAMERA        0x04     // render_obj_camera
#define IS_TYPE_CUBE          0x05     // render_obj_cube
#define IS_TYPE_WIDGET        0x06     // render_obj_widget (base for all widgets)
#define IS_TYPE_WIDGET_LABEL  0x07     // render_obj_widget_label
#define IS_TYPE_WIDGET_CONTA  0x08     // render_obj_widget_container

// RENDER GL NAMES DISCRIMINATION
#define IS_GL_NAME_OBJ        0
#define IS_GL_NAME_SELECTOR   1
#define IS_GL_NAME_PARAM      3

// RENDER_OBJ SELECTORS
#define IS_SEL(x)             ((x)<<2 | IS_GL_NAME_SELECTOR)  // do not use this one directly
#define IS_SEL_NONE           0
#define IS_SEL_MOVE           IS_SEL(0x01)
#define IS_SEL_DELETE         IS_SEL(0x02)
#define IS_SEL_CENTER         IS_SEL(0x03)
#define IS_SEL_USER(x)        IS_SEL((x)<<14)

// MOUSE BUTTONS
#define IS_BUTTON_LEFT        1
#define IS_BUTTON_MIDDLE      2
#define IS_BUTTON_RIGHT       3

// MATRIX
#define IS_MAT4X4             16

class ogl_window;
class event_mng;
class render_mng;

class introsight: public reference_counter
{
    ogl_window *w;
    event_mng *em;
    render_mng *rm;

    // PRIVATE METHODS
    void ctor();
    void dtor();

public:
    introsight();
    virtual ~introsight();

    bool init();
    int refresh();
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	introsight
	{
		# members
		w, em, rm:
						select, read_only

		# methods
		init,
		refresh:
						select

		# special methods
		init:				postunpickle
		refresh:			event_queue
	}
   )
*/
